package com.hanson.demo.queue.kafka;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import com.hanson.demo.actors.Message;
import com.hanson.demo.queue.TbQueueCallback;
import com.hanson.demo.queue.TbQueueProducer;

import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Component
@ConditionalOnProperty(prefix = "queue", value = "type", havingValue = "kafka")
public class KafkaQueueProducter implements TbQueueProducer<Message>{

	private final KafkaTemplate<String, String> kafkaTemplate;
	@Override
	public void init() {
		
	}

	@Override
	public String getDefaultTopic() {
		return null;
	}

	@Override
	public void send(String tpi, Message msg, TbQueueCallback callback) {
		kafkaTemplate.send(tpi, JSONUtil.toJsonStr(msg));
	}

	@Override
	public void stop() {
		
	}

}
